package com.digitalchina.dcn.dcss.web.controller;

import com.digitalchina.dcn.dcss.web.model.Resource;
import com.digitalchina.dcn.dcss.web.service.UserService;
import com.digitalchina.dcn.dcss.web.bind.annotation.CurrentUser;
import com.digitalchina.dcn.dcss.web.model.User;
import com.digitalchina.dcn.dcss.web.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Set;

/**
 * 公共视图控制器
 * 
 * @author starzou
 * @since 2014年4月15日 下午4:16:34
 **/
@Controller
public class IndexController {

    @Autowired
    private ResourceService resourceService;
    @Autowired
    private UserService userService;


    /**
     * 首页
     * 
     * @return
     */
    @RequestMapping("index")
    public String index(@CurrentUser User loginUser, Model model) {
        Set<String> permissions = userService.findPermissions(loginUser.getUsername());
        List<Resource> menus = resourceService.findMenus(permissions);
        model.addAttribute("menus", menus);
        return "index";
    }

}